#27.移除元素

class Solution(object):
    def removeElement(self, nums, val):
        """
        :type nums: List[int]
        :type val: int
        :rtype: int
        """
        k = 0
        result = []
        for i in range(len(nums)):
            if nums[i] != val:
                result.append(nums[i])
                k += 1

        for i in range(k, len(nums)):
            result.append('_')

        for i in range(len(nums)): #遍历复制列表
            nums[i] = result[i]

        return k

nums = [3, 2, 2, 3]
val = 3
solution = Solution()
new_length = solution.removeElement(nums, val)
print("与val不同的数量", new_length)
print("修改后的列表:", nums)